package com.pattern.adapter;

import java.util.Arrays;

/**
 * @author Mr.yuan
 * @version v1.0
 * @date 2019/7/26 15:01
 **/
public class AdapterPattern {
    public static void main(String[] args) {
        AudioPlayer player = new AudioPlayer();
        player.play("mp3", "the first snow of 2002 year");
        player.play("mp4", "the world end");
        player.play("vlc", "the jack singsong");
        player.play("avi", "the japan hot");
    }


    private interface MediaPlayer{
        void play(String type,String content);
    }
    static class AudioPlayer implements MediaPlayer{
        private PlayerAdapter adapter;
        @Override
        public void play(String type,String content) {
            if (type.equalsIgnoreCase("mp3")){
                System.out.println("use mp3Player play");
            }else if (type.equalsIgnoreCase("mp4") || type.equalsIgnoreCase("vlc")){
                adapter = new PlayerAdapter(type);
                adapter.play(type,content);
            }else {
                System.out.println("invalid media."+type+" format");
            }
        }
    }
    interface AdvanceMediaPlayer{
        void play(String content);
    }
    static class Mp4Player implements AdvanceMediaPlayer{
        @Override
        public void play(String content) {
            System.out.println("use mp4Player play");
        }
    }
    static class VlcPlayer implements AdvanceMediaPlayer{
        @Override
        public void play(String content) {
            System.out.println("use vlcPlayer play");
        }
    }

    static class PlayerAdapter implements MediaPlayer{
        private AdvanceMediaPlayer advanceMediaPlayer;

        PlayerAdapter(String type) {
            if (type.equalsIgnoreCase("mp4")){
                advanceMediaPlayer =  new Mp4Player();
            }
            if (type.equalsIgnoreCase("vlc")){
                advanceMediaPlayer =  new VlcPlayer();
            }
        }

        @Override
        public void play(String type, String content) {
            advanceMediaPlayer.play(content);
        }
    }

}
